﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.ObjectModel;
using System.Data;
using AcctrueWMS.Foundation.Common.Exception;

namespace AcctrueWMS.Foundation.Data
{
    class ArrayExpressionEvaler:IExpressionEvaler
    {       
        public CommandExpressionTypeEnum ExpressionType
        {
            get
            {
                return CommandExpressionTypeEnum.Array;
            }
        }
        public IDataModelContext Context
        {
            get;
            set;
        }

        public object Eval(string expr)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("key", typeof(string));
            dt.Columns.Add("value", typeof(string));
            dt.Columns.Add("text", typeof(string));

            //分析字符串，并以DataTable形式返回
            foreach (string itemstr in expr.Split(','))
            {
                DataRow row = dt.NewRow();
                string[] va=itemstr.Split(':');
                for(int i=0;i<va.Length;i++)
                {
                    if (i >= 2)
                        throw new WMSSysException("array命令值分隔符超过3个");
                    row[i] = va[i];
                }
                dt.Rows.Add(row);
            }
            return dt;
        }
    }
}
